<?php

require_once 'common.php';



/**
 * class Guestbook
 * 
 * Guestbook data model abstraction
 * 
 * @author Kirill Krasnoschekov
 */
abstract class Guestbook 
{
    // Number of messages displayed on one page
    protected $messagesPerPage = 10;   
    
    // Error text messages
    protected static $err = array(
        'MSGID_NOT_FOUND' => 'No message with given Id found!',
        'COMMENTID_NOT_FOUND' => 'No comment with given Id found!');


    
    public abstract function __construct();
    public abstract function __destruct();
    
    public function SetMessagesPerPage($messagesPerPage) 
    {
        $this->messagesPerPage = $messagesPerPage;
    }

    public abstract function CountPages();

    /**
     * Fetch messages on the given page
     * 
     * Pages are indexed from 0 to ($this->CountPages - 1).
     * Message: dictionary (id, name, text, timestamp)
     *
     * @return array
     */    
    public abstract function FetchMessages($page);
    
    /**
     * Fetch comments to the given message
     * 
     * comment: dictionary (id, msgid, name, text, timestamp)
     * 
     * @return array
     */
    public abstract function FetchComments($msgid);
    
    public abstract function AddMessage($name, $text);
    public abstract function AddComment($msgid, $name, $text);
    
    public abstract function DeleteMessage($msgid);
    public abstract function DeleteComment($commentid);
    
    public abstract function UpdateMessage($msgid, $name, $text);
    
    

    /**
     * MessageExists
     * 
     * @param int $msgid Message ID
     * @return True if yes, False if no
     */    
    protected abstract function MessageExists($msgid);
    
    /**
     * CommentExists
     * 
     * @param int $commentid Comment ID
     * @return True if yes, False if no
     */    
    protected abstract function CommentExists($commentid);    
}

?>